<template>
  <div>
    <tablePaging :tableItem="tableItem" :operationItem="operationItem" />
    <fileImport v-model:importVisible="importVisible" :importItem="importItem" @onError="onError"
                @onSuccess="onSuccess"/>
  </div>
</template>
<script setup>
import tablePaging from '@/views/common/component/table-paging'
import {onMounted, reactive, ref} from 'vue'
import {operationItem, tableItem} from './const.js'
import {useRouter} from 'vue-router'
import fileImport from '@/views/common/component/fileImport'

const { proxy } = getCurrentInstance();
const router = useRouter()
const data = reactive({

})

function initTableItem() {
  let menuArray = operationItem.menuArray
  let addMenu = menuArray.find(item => item.code === 'add')
  // let inducts = menuArray.find(item => item.code === 'inducts')
  operationItem.menuArray[1].handle = () => {
    importHandle()
  }
  addMenu.handle = goAdd
  // inducts.handle = importHandle

  let btnArray = tableItem.btnArray
  // let detailBtn = btnArray.find(item => item.code === 'detail')
  // detailBtn.handle = goDetail

  let editBtn = btnArray.find(item => item.code === 'edit')
  editBtn.handle = goEdit
}

const initOptions = () => {

}
let importVisible = ref(false)
const importItem = reactive({
  downUrl: '/admin/order/download',//模板下载地址
  upUrl: '/admin/order/user/batch/import',//文件上传地址
  blob: true,//二进制文件下载
  fileDown() {
  },//自定义文件下载方法 如果传入下载地址会失效 如果都不传会返回一个fileDown函数 自己@fileDown接收
  downTitle: '',//下载标题 默认1、模板下载
  downButtonText: '',//下载按钮 下载
  upButtonText: '',//上传按钮 上传
  upTitle: '',//上传标题 默认2、表格上传
  downName: '订单导入模板'
})
const importHandle = () => {
  importVisible.value = true
}
const onSuccess = (e) => {
  tableItem.pageInfo.paging()
}
const onError = (e) => {
}
const goAdd = () => {
  router.push({
    path: '/modules/order/order/save',
    query: {type: 'add'}
  })
}

const goEdit = (row) => {
  router.push({
    path: '/modules/order/order/save',
    query: { id: row.id, type: 'edit'}
  })
}

const goDetail = (row) =>{
  router.push({
    path: '/modules/order/order/detail',
    query: { id: row.id}
  })
}

onMounted(() => {
  initTableItem()
  initOptions()
})
</script>

<style></style>
